<meta charset="UTF-8">
<?php

require ('lib/init.php');
// 判断用户是否登录
if (!acc()) {
    header('Location:login.php');
}
$cat_id = $_GET['cat_id'];
//检测分类是否合法
if (!is_numeric($cat_id)){
    error('文章分类不合法！','javascript:history.back(-1)');
    exit();
}
//检测栏目是否存在
$sql = "select count(*) from cat where cat_id = $cat_id";
$rs = mGetOne($sql);
if ($rs[0] == 0){
    error('文章栏目不存在！','javascript:history.back(-1)');
    exit();
}


if (empty($_POST)){
    $sql = "select cat_name from cat where cat_id = $cat_id";
    $cat = mGetRow($sql);
    require ('view/admin/catedit.html');
}else{
    if (trim($_POST['catname']) == '') error('栏目名不能修改为空格!','javascript:history.back(-1)');
    $newcat = trim($_POST['catname']);
    $sql = "update cat set cat_name = '$newcat' where cat_id=$cat_id";
    if (!mQuery($sql)){
        error('分类修改失败！','javascript:history.back(-1)');
    }
    else {
        error('分类修改成功！','catlist.php');
    }

}


?>
